package com.freightoa.foundation.net

import com.freightoa.foundation.app.MMKVUtils
import com.freightoa.foundation.app.MMKVkEY
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response

/**
 * 作者：lhgray on 2025/3/28.
 * 邮箱：lhgray@163.com
 * 文件：com.freightoa.foundation.net
 */
// 自定义拦截器，用于在请求头添加数据
class HeaderInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        // 获取原始请求
        val originalRequest: Request = chain.request()
        // 构建新的请求，添加自定义请求头
        val newRequest: Request = originalRequest.newBuilder()
            .addHeader("appKey", MMKVUtils.getString(MMKVkEY.appKey, ""))
            .addHeader("appToken", MMKVUtils.getString(MMKVkEY.appToken, ""))
            .build()
        // 继续执行请求
        return chain.proceed(newRequest)
    }
}